import React, { useState, useEffect } from 'react'
import dva from './images/dva.png'

export default function Test() {
  const [position, setPosition] = useState({
    left: 0,
    top: 0,
  })
  useEffect(() => {
    const move = (e) => {
      console.log(1)
      setPosition({
        left: e.pageX,
        top: e.pageY,
      })
    }
    document.addEventListener('mousemove', move)
    return () => {
      document.removeEventListener('mousemove', move)
    }
  }, []) // componentDidMount
  return (
    <div>
      <img
        src={dva}
        style={{
          width: 100,
          position: 'absolute',
          left: position.left - 50,
          top: position.top + 50,
        }}
        alt='dva'
      />
    </div>
  )
}
